package com.demo.project_template.base.pay.wxpay.controller;


import com.demo.project_template.base.pay.wxpay.service.WeChatNotifyService;
import com.demo.project_template.base.pay.wxpay.vo.WxPayAsyncReturnVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.GeneralSecurityException;


/**
 * @author ZhangKeChen
 * @date 2022/8/19
 */
@Slf4j
@RestController
@RequestMapping("/api/wechat")
public class WeChatNotifyController {
    @Resource
    private WeChatNotifyService weChatPayService;

    /**
     * 项目 订单支付回掉
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @PostMapping("/orderNotify")
    public WxPayAsyncReturnVo orderNotify(HttpServletRequest request, HttpServletResponse response)  {
        return weChatPayService.orderNotify(request, response);
    }

    /**
     * 用户充值订单回掉
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws GeneralSecurityException
     */
    @PostMapping("/rechargeNotify")
    public WxPayAsyncReturnVo rechargeNotify(HttpServletRequest request, HttpServletResponse response)  {
        return weChatPayService.rechargeNotify(request, response);
    }
}
